package com._901_惠科_QD_去重_;

import com.alibaba.fastjson.JSON;

import java.time.LocalDateTime;
import java.util.ArrayList;

/**
 * 这种的你看下能否把查询的数据优化一下,要的效果是这样的:
 * 现在的数据是:
 * 卡号      x坐标     y坐标           时间
 * 1         10        10          19:21:21:000
 * 1         10        10          19:21:22:000
 * 1         10        10          19:21:23:000
 * 1         10        10          19:21:24:000
 * 1         10        10          19:21:25:000
 * 1         10.1     10.1         19:21:26:000
 * 1         11        11          19:21:27:000
 *
 * <p>
 * 传 19:21:00~19:22:00 时间参数后,查出来之后是:
 * 卡号    x坐标    y坐标    时间
 * 1         10        10          19:21:21:000
 * 1         11        11          19:21:26:000
 * <p>
 * 就是把某一个时间段内的 如果坐标相差不超过1的汇总成1条记录
 */
public class Start {
    //     * @param beforeX 上一条数据的 X坐标
    //     * @param beforeY 上一条数据的 Y坐标
    //     * @param X_Sill  X_阀值
    //     * @param Y_Sill  Y_阀值
    private static Double beforeX = 0.0;
    private static Double beforeY = 0.0;
    private static Double X_Sill = 1.0;
    private static Double Y_Sill = 1.0;

    public static void main(String[] args) {

        PositionEntity positionEntity1 = new PositionEntity();
        positionEntity1.setCardId("1");
        positionEntity1.setCardX(10.0);
        positionEntity1.setCardY(10.0);
        positionEntity1.setTime(LocalDateTime.of(2021, 7, 7, 19, 21, 21, 0));

        PositionEntity positionEntity2 = new PositionEntity();
        positionEntity2.setCardId("1");
        positionEntity2.setCardX(10.0);
        positionEntity2.setCardY(10.0);
        positionEntity2.setTime(LocalDateTime.of(2021, 7, 7, 19, 21, 22, 0));

        PositionEntity positionEntity3 = new PositionEntity();
        positionEntity3.setCardId("1");
        positionEntity3.setCardX(10.0);
        positionEntity3.setCardY(10.0);
        positionEntity3.setTime(LocalDateTime.of(2021, 7, 7, 19, 21, 23, 0));

        PositionEntity positionEntity4 = new PositionEntity();
        positionEntity4.setCardId("1");
        positionEntity4.setCardX(10.0);
        positionEntity4.setCardY(10.0);
        positionEntity4.setTime(LocalDateTime.of(2021, 7, 7, 19, 21, 24, 0));

        PositionEntity positionEntity5 = new PositionEntity();
        positionEntity5.setCardId("1");
        positionEntity5.setCardX(10.0);
        positionEntity5.setCardY(10.0);
        positionEntity5.setTime(LocalDateTime.of(2021, 7, 7, 19, 21, 25, 0));

        PositionEntity positionEntity6 = new PositionEntity();
        positionEntity6.setCardId("1");
        positionEntity6.setCardX(10.1);
        positionEntity6.setCardY(10.1);
        positionEntity6.setTime(LocalDateTime.of(2021, 7, 7, 19, 21, 26, 0));

        PositionEntity positionEntity7 = new PositionEntity();
        positionEntity7.setCardId("1");
        positionEntity7.setCardX(11.0);
        positionEntity7.setCardY(11.0);
        positionEntity7.setTime(LocalDateTime.of(2021, 7, 7, 19, 21, 27, 0));
        ArrayList<PositionEntity> list = new ArrayList<>();
        list.add(positionEntity1);
        list.add(positionEntity2);
        list.add(positionEntity3);
        list.add(positionEntity4);
        list.add(positionEntity5);
        list.add(positionEntity6);
        list.add(positionEntity7);


        ArrayList<PositionEntity> newEntityList = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            PositionEntity entity = list.get(i);
            boolean valid = entity.isValid(beforeX, beforeY, X_Sill, Y_Sill);
            if (valid) {
                beforeX = entity.getCardX();
                beforeY = entity.getCardY();
                newEntityList.add(entity);
            }
        }
        System.out.println("原始数据展示: " + JSON.toJSONString(list));
        System.out.println("去重后数据展示: " + JSON.toJSONString(newEntityList));
    }
//去重后数据展示: [{"cardId":"1","cardX":10.0,"cardY":10.0,"time":"2021-07-07 19:21:21"},{"cardId":"1","cardX":11.0,"cardY":11.0,"time":"2021-07-07 19:21:27"}]
/**=================原始数据展示=============================
 * [
 *     {
 *         "cardId":"1",
 *         "cardX":10,
 *         "cardY":10,
 *         "time":"2021-07-07 19:21:21"
 *     },
 *     {
 *         "cardId":"1",
 *         "cardX":10,
 *         "cardY":10,
 *         "time":"2021-07-07 19:21:22"
 *     },
 *     {
 *         "cardId":"1",
 *         "cardX":10,
 *         "cardY":10,
 *         "time":"2021-07-07 19:21:23"
 *     },
 *     {
 *         "cardId":"1",
 *         "cardX":10,
 *         "cardY":10,
 *         "time":"2021-07-07 19:21:24"
 *     },
 *     {
 *         "cardId":"1",
 *         "cardX":10,
 *         "cardY":10,
 *         "time":"2021-07-07 19:21:25"
 *     },
 *     {
 *         "cardId":"1",
 *         "cardX":10.1,
 *         "cardY":10.1,
 *         "time":"2021-07-07 19:21:26"
 *     },
 *     {
 *         "cardId":"1",
 *         "cardX":11,
 *         "cardY":11,
 *         "time":"2021-07-07 19:21:27"
 *     }
 * ]
 */
}
